package com.jdojo.shape;

/**
 * @author zhufeifei
 * @date 2024-04-22 11:00
 */

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.List;

public class TextFontTest extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        Text t1 = new Text();
        t1.setText(t1.getFont().toString());
        Text t2 = new Text();
        t2.setFont(Font.font("Arial", 12));
        t2.setText(t2.getFont().toString());
        Text t3 = new Text();
        t3.setFont(Font.font("Arial", FontWeight.BLACK, 12));
        t3.setText(t3.getFont().toString());
        Text t4 = new Text();
        t4.setFont(Font.font("Arial", FontWeight.THIN, FontPosture.ITALIC, 12));
        t4.setText(t4.getFont().toString());
        VBox root = new VBox(t1, t2, t3, t4);
        root.setSpacing(10);
        root.setStyle("-fx-padding: 10;" +
                "-fx-border-style: solid inside;" +
                "-fx-border-width: 2;" +
                "-fx-border-insets: 5;" +
                "-fx-border-radius: 5;" +
                "-fx-border-color: blue;");
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Setting Fonts for Text Nodes");
        stage.show();

        // 获取系统中所有已安装字体的具体名称列表
        List<String> fontNames = Font.getFontNames();

        // 遍历每个字体名称，获取字体家族名称
        for (String fontName : fontNames) {
            // 使用字体名称创建一个 Font 对象
            Font font = Font.font(fontName, 12); // 使用默认字体大小，这里选择 12

            // 获取字体家族名称并输出
            String fontFamily = font.getFamily();
            System.out.println("Font Name: " + fontName + ", Font Family: " + fontFamily);
        }
    }
}